<UserControl
  x:Name="This"
  x:Class="ImmlPad.Views.DocumentsView"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:v="clr-namespace:ImmlPad.Views"
  xmlns:a="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
  xmlns:d="clr-namespace:ImmlPad.DocumentViews">

  <UserControl.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary   Source="/Resources/EditorTabControl.xaml" />
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </UserControl.Resources>

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="25" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>


    <TabControl
      x:Name="DocumentTabControl"
      Style="{StaticResource EditorTabControl}"
      ItemsSource="{Binding ElementName=This, Path=XmlDocuments}"
      SelectedItem="{Binding ElementName=This, Path=SelectedDocument, Mode=TwoWay}">
      <TabControl.Resources>
        <Style x:Key="{x:Type ToolTip}" TargetType="{x:Type ToolTip}">
          <Setter Property="OverridesDefaultStyle" Value="true"/>
          <Setter Property="HasDropShadow" Value="False"/>
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type ToolTip}">
                <ContentPresenter/>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>
      </TabControl.Resources>

      <!--<TabControl.ContentTemplate>
      <DataTemplate>
        <d:WPFDocumentView Loaded="DocumentViewLoaded" DataContextChanged="DocumentViewChanged" />
      </DataTemplate>
    </TabControl.ContentTemplate>-->

      <TabControl.ItemTemplate>
        <DataTemplate>
          <Grid Margin="-10" Background="#0f00" ToolTipService.InitialShowDelay="1000">
            <Grid.ToolTip>
              <a:SystemDropShadowChrome SnapsToDevicePixels="True" CornerRadius="4" Margin="0,0,5,5" HorizontalAlignment="Center" VerticalAlignment="Center">
                <Grid >
                  <Border CornerRadius="4" BorderBrush="#8FFF"  BorderThickness="0,1,0,0">
                    <Border.Background>
                      <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Offset="0.0" Color="#C0606060" />
                        <GradientStop Offset="1.0" Color="#C0303030" />
                      </LinearGradientBrush>
                    </Border.Background>
                  </Border>
                  <Border CornerRadius="4" Width="160" Height="110" Margin="8" >
                    <Border.Background>
                      <ImageBrush ImageSource="{Binding PreviewImage}" Stretch="UniformToFill" />
                    </Border.Background>
                  </Border>
                </Grid>
              </a:SystemDropShadowChrome>
            </Grid.ToolTip>
            <Grid.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Open with Player" Click="OpenWithPlayer" />
                                <MenuItem Header="Open with Player v1.5" Click="OpenWithPlayer_CodenameFreedom" Visibility="{Binding ElementName=This, Path=CodenameFreedomVisibility}"/>
                                <MenuItem Header="Open containing folder" Click="OpenContainingFolder"/>
                                <Separator />
                                <MenuItem Header="Close" Click="Close_Click"/>
                                <MenuItem Header="Close all but this" Click="CloseAllButThis_Click"/>
                                <MenuItem Header="Close all" Click="CloseAll_Click"/>
                            </ContextMenu>
                        </Grid.ContextMenu>
                <TextBlock Margin="4">
            <TextBlock Text="{Binding Filename}" />
            <TextBlock x:Name="Star" Text="*" Margin="-4,0,0,0" Visibility="Collapsed" />
          </TextBlock>
          </Grid>
          <DataTemplate.Triggers>
            <!--<DataTrigger Binding="{Binding NeedsSave}" Value="False">
              <Setter TargetName="Star" Property="Visibility" Value="Collapsed" />
            </DataTrigger>-->
            <DataTrigger Binding="{Binding NeedsSave}" Value="True">
                <Setter TargetName="Star" Property="Visibility" Value="Visible" />
            </DataTrigger>
        </DataTemplate.Triggers>
        </DataTemplate>
      </TabControl.ItemTemplate>

    </TabControl>
    
    <ListBox
      x:Name="ContentListBox"
      Grid.Row="1"
      ItemsSource="{Binding ElementName=This, Path=XmlDocuments}"
      SelectedItem="{Binding ElementName=This, Path=SelectedDocument}">
      <ListBox.Template>
        <ControlTemplate TargetType="{x:Type ListBox}">
          <Grid IsItemsHost="True" />
        </ControlTemplate>
      </ListBox.Template>
      <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
          <Setter Property="OverridesDefaultStyle" Value="True" />
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate TargetType="{x:Type ListBoxItem}">
                <d:ImmlDocumentView x:Name="PART_DocumentView" Loaded="DocumentViewLoaded" Visibility="Collapsed" />
                <ControlTemplate.Triggers>
                  <Trigger Property="IsSelected" Value="True">
                    <Setter TargetName="PART_DocumentView" Property="Visibility" Value="Visible" />
                  </Trigger>
                </ControlTemplate.Triggers>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>
      </ListBox.ItemContainerStyle>
      <!--<ListBox.ItemTemplate>
        <DataTemplate>
          <d:WPFDocumentView x:Name="PART_DocumentView" Loaded="DocumentViewLoaded" />
        </DataTemplate>
      </ListBox.ItemTemplate>-->
    </ListBox>

  </Grid>

</UserControl>
